package com.example.teaculture.activity;

import android.app.ListActivity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.appcompat.widget.Toolbar;

import com.example.teaculture.DB.DBOpenHelper;
import com.example.teaculture.DB.HistoryDao;
import com.example.teaculture.R;
import com.example.teaculture.tools.Favor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HistoryActivity extends ListActivity {
    private Toolbar toolbar;
    private DBOpenHelper helper;
    private SQLiteDatabase sd;
    private ArrayList<Favor> historylist;
    private List<Map<String, String>> data = new ArrayList<Map<String,String>>();
    private ListView lv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history);
        toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle("浏览记录");
        //创建或打开数据库
        helper = new DBOpenHelper(HistoryActivity.this);
        sd = helper.getReadableDatabase();
        historylist = new ArrayList<>();
        //扫描数据库,将数据库信息放入studentlist
        Favor history=new Favor();
        HistoryDao historyDao=new HistoryDao(HistoryActivity.this);
        List<Favor> list =historyDao.findSelected();
        if(list!=null){
            for(int i = 0 ; i<list.size();i++){
                Log.i("TAG:","    " +list.get(i).getTitle());
                Map<String, String> map = new HashMap<String, String>();
                map.put("标题", list.get(i).getTitle());
                data.add(map);
            }
        }
        setListAdapter(new SimpleAdapter(this, data, android.R.layout.simple_list_item_1,
                new String[]{"标题"},            //每行显示一个姓名
                new int[]{android.R.id.text1}   //名字在text1上显示
        ));
    }
public void hback(View view){
      this.finish();
}
}

